<!-- 导入excel -->
<template>
    <a-upload-dragger accept=".xls,.xlsx" name="file" :customRequest="upload" :headers="headers" :before-upload="beforeUpload"
        :showUploadList="false">
        <slot></slot>
    </a-upload-dragger>
</template>

<script>
import Vue from 'vue'
import { ACCESS_TOKEN, TENANTID } from '@/store/mutation-types'
import { mimeMap } from '@/utils/download'

export default {
    components: {},
    data() {
        return {
            headers: {
                token: Vue.ls.get(ACCESS_TOKEN),
                tenantId: Vue.ls.get(TENANTID)
            },
        }
    },
    computed: {},
    watch: {},
    methods: {
        // 导入前校验
        beforeUpload(file) {
            const bool = file.type === mimeMap.xls || file.type === mimeMap.xlsx
            if (!bool) {
                this.$message.error('请上传excel文件!')
            }
            return bool
        },
        upload(params){
            const file = params.file
            // 根据后台需求数据格式
            var form = new FormData()
            // 文件对象
            form.append('file', file)
            this.$emit('upload', form)
        }
    },
    created() {

    },
    mounted() {

    },
}
</script>
<style scoped>

</style>